import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:flutter_wifi/page/WebBasePage.dart';
import 'package:mybase/base/tool/api/ApiUtils.dart';
import 'package:mybase/base/tool/api/IAppEnv.dart';
import 'package:mybase/base/tool/globalMethod/FFSafeValue.dart';
import 'package:mybase/base/tool/web/FFWebHelp.dart';

void main() {
  // 设置上传的url
  var uri = Uri.base;
  var map = FFWebHelp.uriToMap(uri.path);
  String title = globalSafeValueFromMap(map, "t") ?? "";
  FFWebHelp.setTitleAndPath(title: title, path: uri.path);

  var env = MyEnv();
  env.env_product = kDebugMode ? "http://192.168.0.102:3333/" : "http://${uri.host}:${uri.port}/";
  // env.env_product = "http://${uri.host}:${uri.port}/";
  ApiUtils.appApi = env;
  ApiUtils.httpClientAdapter = false;
  runApp(MyApp(
    title: title,
  ));
}

class MyApp extends StatelessWidget {
  String title;

  MyApp({
    super.key,
    required this.title,
  });

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: title,
      builder: FlutterSmartDialog.init(),
      home: WebBasePage(),
    );
  }
}

///默认配置，啥也没有
class MyEnv implements IAppEnv {
  @override
  bool isProduct = true;

  @override
  bool isShowTestBtn = false;

  @override
  String env_local = "";

  @override
  String env_product = "";

  @override
  bool printApiData = true;

  @override
  Map<String, String>? setHeader(Map<String, String>? headers) {
    return headers;
  }

  @override
  String getCurrentBaseUrl() {
    return "";
  }
}
